package auction.chapter16.factory.impl;

import auction.chapter16.dao.BidDAO;
import auction.chapter16.dao.ItemDAO;
import auction.chapter16.dao.UserDAO;
import auction.chapter16.dao.hibernate.GenericHibernateDAO;
import auction.chapter16.dao.hibernate.ItemDAOHibernate;
import auction.chapter16.factory.DAOFactory;
import auction.model.Bid;
import auction.model.User;

public class HibernateDAOFactory extends DAOFactory {

	public ItemDAO getItemDAO() {
		return (ItemDAO)instantiateDAO(ItemDAOHibernate.class);
	}

	public BidDAO getBidDAO() {
		return (BidDAO)instantiateDAO(BidDAOHibernate.class);
	}
	
	public UserDAO getUserDAO() {
		return (UserDAO)instantiateDAO(UserDAO.class);
	}
	
	private GenericHibernateDAO instantiateDAO(Class daoClass){
		try{
			GenericHibernateDAO dao=(GenericHibernateDAO)daoClass.newInstance();
			return dao;
		}catch(Exception ex){
			throw new RuntimeException("Can not instantiate DAO: "+daoClass,ex);
		}
	}
	
	
	//Inline all empty DAO implementations
	
	public static class BidDAOHibernate extends GenericHibernateDAO<Bid,Long> implements BidDAO{
		
	}
	
	public static class UserDAOHibernate extends GenericHibernateDAO<User,Long> implements UserDAO{
		
	}

}
